﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Text;
using System.Windows.Forms;

namespace GraphicImageView
{
    public partial class GraphicImageControl : UserControl
    {
       public HpmipNet.GraphicImagePresenter presenter = null;
       private HpmipNet.GraphicImageRotateController rotController = null;
    
       private bool loaded = false;
      

        public GraphicImageControl()
        {
            InitializeComponent();

            presenter = new HpmipNet.GraphicImagePresenter(this.Handle, this.Width, this.Height,"OpenGL");
            rotController = new HpmipNet.GraphicImageRotateController(presenter);
        }

        public void SetModel(HpmipNet.GraphicImageModel model)
        {
            if (presenter != null)
            {
                presenter.SetModel(model);
            }
        }

  
         protected override void OnPaint(PaintEventArgs e)
         {
             if (!loaded) return;

             base.OnPaint(e);
             if (presenter != null)
               presenter.OnPaint();
         }
         protected override void OnSizeChanged(EventArgs e)
         {
             if (!loaded) return;
             base.OnSizeChanged(e);
                 if (presenter != null)
                   presenter.OnSizeChanged(this.Width, this.Height);
         }

         protected override void OnMouseDown(MouseEventArgs e)
         {
             if (!loaded) return;
             base.OnMouseDown(e);

             if (rotController != null)
                 rotController.OnMouseDown(e.X, e.Y);
         }

         protected override void OnMouseMove(MouseEventArgs e)
         {
             if (!loaded) return;
             base.OnMouseMove(e);
             if (rotController != null)
                 rotController.OnMouseMove(e.X, e.Y);


         }
         protected override void OnMouseUp(MouseEventArgs e)
         {
             if (!loaded) return;
             base.OnMouseUp(e);

             if (rotController != null)
                 rotController.OnMouseUp(e.X, e.Y);
         }

       

         private void GraphicImageControl_Load(object sender, EventArgs e)
         {
             loaded = true;
             presenter = new HpmipNet.GraphicImagePresenter(this.Handle, this.Width, this.Height,"OpenGL");
         }

    }
}
